/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Dao;

import Interface.InterfaceFirstName;
import Pojo.Firstname;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author knyazev_o
 */
public class DaoFirstName implements InterfaceFirstName{

    @Override
    public boolean register(Session session, Firstname firstName) throws Exception {
        session.save(firstName);        
        return true;
    }

    @Override
    public List<Firstname> getAll(Session session) throws Exception {
        String hql="from Firstname";
        Query query=session.createQuery(hql);        
        List<Firstname> listFirstName =(List<Firstname>) query.list();        
        return listFirstName;
    }
    
    @Override
    public boolean update(Session session, Firstname firstName) throws Exception {
        session.update(firstName);
        return true;
    }

    @Override
    public boolean delete(Session session, Firstname firstName) throws Exception {
        session.delete(firstName);
        return true;
    }

    @Override
    public Firstname selectFirstName(Session session, String hql, List<Object> param) throws Exception {
        Query query=session.createQuery(hql);
        for(Object inParam:param){
            query.setParameter(param.indexOf(inParam), inParam);
        }
        Firstname firstName=(Firstname) query.uniqueResult();        
        return firstName;
    }

    @Override
    public List<Firstname> selectListFirstName(Session session, String hql, List<Object> param) throws Exception {
        Query query=session.createQuery(hql);
        for(Object inParam:param){
            query.setParameter(param.indexOf(inParam), inParam);
        }       
        List<Firstname> listFirstName =(List<Firstname>) query.list();        
        return listFirstName;
    }
    
}
